﻿$(function() {$('input#nfnumber').autocomplete(base + 'order.ivp/findnotarialformnumber?all=true').result(function(e,d) {var obj = $(e.target); obj.val(''); addItem(d[1], d[2]); return false;});});

function addItem(id, name) {
	$('select#ids').append('<option selected="selected" value="' + id + '">' + id + '</option>');
	var list = $('ul.data');	
	list.append('<li><a class="noul nfinvalidlink" onclick="return remove(this, '+id+');" href="#"><img title="Удалить" src="img/trash.gif"></a><span class="paddedleft20">'+name+'</span></li>');	
	return false;
}

function remove(a, id) {
	var a = $(a);
	var select = $('select#ids');
	$('option[value="' + id + '"]', select).remove();
	a.parent().remove();
	return false;
}

function clearData() {
	$('ul.data li').remove();
	return false;
}

function changeStatus() {
	if ($('select#ids option').length == 0) 
	{
		alert('Не выбран ни один бланк');
		return false;
	}

	var ids = new Array();
	$('select#ids option').each(function() { ids.push($(this).val());});
	
	$.getJSON('notarialform.ivp/ChangeStatusForGroup/', { timestamp: new Date(), ids: ids.join(','), statusid:$('#statusid').val() }, function(result) {
		if (result.hasOwnProperty('IsOK') && result.IsOK == true) 
			clearData();
		if (result.Description.length > 0)
			alert(result.Description);		
	});   
	
	return false;
}